<template>
  <div id="app" class="min-h-screen">
    <!-- 路由视图 -->
    <router-view />
    
    <!-- 全局Toast通知 -->
    <tiny-notify-container />
    
    <!-- 全局Loading -->
    <div v-if="appStore.loading" class="global-loading">
      <div class="loading-backdrop"></div>
      <div class="loading-content glass-card">
        <tiny-loading size="large" text="加载中..." />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted } from 'vue'
import { useAppStore } from '@/stores/app'
import { useAuthStore } from '@/stores/auth'

const appStore = useAppStore()
const authStore = useAuthStore()

onMounted(async () => {
  // 初始化应用
  await appStore.initialize()
  
  // 验证用户登录状态
  await authStore.checkAuth()
})
</script>

<style lang="scss">
// 全局加载遮罩样式
.global-loading {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  
  .loading-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
  }
  
  .loading-content {
    position: relative;
    padding: $spacing-8;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: $spacing-4;
    
    .tiny-loading {
      color: $primary-500;
    }
  }
}

// 暗色主题下的加载样式
[data-theme="dark"] {
  .global-loading {
    .loading-backdrop {
      background: rgba(0, 0, 0, 0.6);
    }
    
    .loading-content {
      background: rgba(37, 45, 63, 0.95);
      border-color: $dark-glass-border;
      
      .tiny-loading {
        color: $primary-400;
      }
    }
  }
}

// 响应式加载样式
@media (max-width: $breakpoint-sm) {
  .global-loading .loading-content {
    margin: $spacing-4;
    padding: $spacing-6;
  }
}
</style>
